﻿using System;
using System.Data;
using System.Collections.Generic;
using OgilvyOne.Model;
using OgilvyOne.DALFactory;
using OgilvyOne.IDAL;
namespace OgilvyOne.BLL
{
    /// <summary>
    /// ActivityManageBll
    /// </summary>
    public partial class ActivityManageBll
    {
        private readonly IActivityManage dal = ActivityManageFactory.create();
        public ActivityManageBll()
        { }
        #region  Method
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int activityId)
        {
            return dal.Exists(activityId);
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        /// <param name="activityName">活动名</param>
        /// <returns></returns>
        public bool Exists(string activityName, int activityId)
        {
            return dal.Exists(activityName, activityId);
        }
        
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(OgilvyOne.Model.ActivityManageModel model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(OgilvyOne.Model.ActivityManageModel model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int activityId)
        {

            return dal.Delete(activityId);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string activityIdlist)
        {
            return dal.DeleteList(activityIdlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public OgilvyOne.Model.ActivityManageModel GetModel(int activityId)
        {

            return dal.GetModel(activityId);
        }
        
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<OgilvyOne.Model.ActivityManageModel> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<OgilvyOne.Model.ActivityManageModel> DataTableToList(DataTable dt)
        {
            List<OgilvyOne.Model.ActivityManageModel> modelList = new List<OgilvyOne.Model.ActivityManageModel>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                OgilvyOne.Model.ActivityManageModel model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new OgilvyOne.Model.ActivityManageModel();
                    if (dt.Rows[n]["activityId"].ToString() != "")
                    {
                        model.Activityid = int.Parse(dt.Rows[n]["activityId"].ToString());
                    }
                    model.Activityname = dt.Rows[n]["ACTIVITY_NAME"].ToString();
                    if (dt.Rows[n]["START_DATE"].ToString() != "")
                    {
                        model.Startdate = DateTime.Parse(dt.Rows[n]["START_DATE"].ToString());
                    }
                    if (dt.Rows[n]["END_DATE"].ToString() != "")
                    {
                        model.Enddate = DateTime.Parse(dt.Rows[n]["END_DATE"].ToString());
                    }
                    model.Activityaddr = dt.Rows[n]["ACTIVITY_ADDR"].ToString();
                    model.Hostunit = dt.Rows[n]["HOST_UNIT"].ToString();
                    model.Activitycontent = dt.Rows[n]["ACTIVITY_CONTENT"].ToString();
                    if (dt.Rows[n]["STATE"].ToString() != "")
                    {
                        model.State = int.Parse(dt.Rows[n]["STATE"].ToString());
                    }
                    if (dt.Rows[n]["ACTIVITY_TYPE"].ToString() != "")
                    {
                        model.Activitytype = int.Parse(dt.Rows[n]["ACTIVITY_TYPE"].ToString());
                    }
                    model.Source = dt.Rows[n]["SOURCE"].ToString();
                    model.Titleimg = dt.Rows[n]["TITLE_IMG"].ToString();
                    if (dt.Rows[n]["IS_HOTS"].ToString() != "")
                    {
                        model.Ishots = int.Parse(dt.Rows[n]["IS_HOTS"].ToString());
                    }
                    model.Hotsimg = dt.Rows[n]["HOTS_IMG"].ToString();
                    if (dt.Rows[n]["IS_KV"].ToString() != "")
                    {
                        model.Iskv = int.Parse(dt.Rows[n]["IS_KV"].ToString());
                    }
                    model.Kvimg = dt.Rows[n]["KV_IMG"].ToString();
                    if (dt.Rows[n]["ADDTIME"].ToString() != "")
                    {
                        model.Addtime = DateTime.Parse(dt.Rows[n]["ADDTIME"].ToString());
                    }
                    model.Addusername = dt.Rows[n]["ADDUSERNAME"].ToString();
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  Method
    }
}

